package org.mobiletrain.www.secondproject2;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RadioGroup;


public class NearbyFragment extends Fragment {
    private String cityCodeNearby;
    private String cityNameNearby;
    String pathtuijian="http://appapi.yaochufa.com/v2/Product/" +
            "GetProductList?pageIndex=1&longitude=&latitude=" +
            "&themeId=&machineCode=865026028677325&version" +
            "=4.2.2&sort=d&system=android&pageSize=20&propertyId=&type" +
            "=around&channel=yaochufa&city="+cityNameNearby+"&tagId=0";
    String pathmenpiao="http://appapi.yaochufa.com/v2/Product/" +
            "GetProductList?pageIndex=1&longitude=&latitude=" +
            "&themeId=&machineCode=865026028677325&version=4.2.2" +
            "&sort=d&system=android&pageSize=20&propertyId=" +
            "&type=around&channel=yaochufa&city="+cityNameNearby+"&tagId=68";


    private NearbySubFragment nearbySubFragment;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_nearby, container, false);

        Bundle bundle = getArguments();
        cityCodeNearby = bundle.getString("cityCodeNearby");
        cityNameNearby = bundle.getString("cityNameNearby");


        RadioGroup  nbfRadioGroup= (RadioGroup) view.findViewById(R.id.nearbyfrag_radiogroup);
        ((RadioButton)nbfRadioGroup.getChildAt(0)).setChecked(true);
        FragmentTransaction fragmentTransaction =
                getActivity().getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.frag_nearby_container,
                new NearbySubFragment()).commit();

        nbfRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();

                switch (checkedId){
                case R.id.nearby_tuijian:
                   Bundle bundle = new Bundle();
                    bundle.putString("path",pathtuijian);
                    nearbySubFragment = new NearbySubFragment();
                    nearbySubFragment.setArguments(bundle);
                    break;
                case R.id.nearby_jiudiantaocan:
                    nearbySubFragment = new NearbySubFragment();
                    break;
                case R.id.nearby_menpiao:
                    Bundle bundlemenpiao = new Bundle();
                    bundlemenpiao.putString("path",pathmenpiao);
                    nearbySubFragment = new NearbySubFragment();
                    nearbySubFragment.setArguments(bundlemenpiao);
                    break;
                case R.id.nearby_juli:
                    PopupWindow window = new PopupWindow(getActivity());

                    break;

            }
                transaction.replace(R.id.frag_nearby_container,nearbySubFragment).commit();

            }
        });

        return view ;
    }


}
